package com.leetcode_mianshi_150;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class RandomizedSet {

    private List<Integer> list;
    public RandomizedSet() {
        list = new ArrayList<>();
    }
    
    public boolean insert(int val) {
        if (list.contains(val)) {
            return false;
        }

        list.add(val);
        return true;
    }
    
    public boolean remove(int val) {
        if (list.contains(val)) {
            list.remove((Object)val);
            return true;
        }

        return false;
    }
    
    public int getRandom() {
        Random random = new Random();

        int size = list.size();
        int randomIndex = random.nextInt(size);

        return list.get(randomIndex);
    }
}